package com.example.shoppingdemo.nslcommodity.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.javabean.ReturnsModel;
import com.example.shoppingdemo.nslcommodity.myview.RoundRectImageView;

import java.util.List;

public class ReturnsAdapter extends RecyclerView.Adapter<ReturnsAdapter.ReturnsHolder>{
   private List<ReturnsModel> returnsModels;
   private Context context;
   private onReturnsParticulars particulars;

    public void setParticulars(onReturnsParticulars particulars) {
        this.particulars = particulars;
    }

    public void setReturnsModels(List<ReturnsModel> returnsModels) {
        this.returnsModels = returnsModels;
    }

    public ReturnsAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public ReturnsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ReturnsHolder holder=new ReturnsHolder(LayoutInflater.from(context).inflate(R.layout.returns_item,parent,false));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ReturnsAdapter.ReturnsHolder holder, int position) {
        Uri uri=Uri.parse(returnsModels.get(position).getIcon());
        Glide.with(context).load(uri).into(holder.icon);
        holder.numder.setText("编号："+returnsModels.get(position).getNumder());
        holder.title.setText(returnsModels.get(position).getTitle());
        holder.sku.setText(returnsModels.get(position).getSku());
        holder.refund.setText("退款：￥"+returnsModels.get(position).getRefund());
        switch (returnsModels.get(position).getRefundType()){
            case 0:
                holder.refundType.setText("待处理");
                break;
            case 1:
                holder.refundType.setText("退货中");
                break;
            case 2:
                holder.refundType.setText("退货成功");
                break;
            case 3:
                holder.refundType.setText("退货失败");
                break;
        }
        holder.details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                particulars.onReturnsResult(holder.getAdapterPosition());
            }
        });
    }

    @Override
    public int getItemCount() {
        return null==returnsModels?0:returnsModels.size();
    }

    class ReturnsHolder extends RecyclerView.ViewHolder{
        TextView numder;
        RoundRectImageView icon;
        TextView title;
        TextView sku;
        TextView refund;
        TextView refundType;
        TextView delete;
        TextView details;
        public ReturnsHolder(@NonNull View itemView) {
            super(itemView);
            numder=itemView.findViewById(R.id.text_item_returns_numder);
            icon=itemView.findViewById(R.id.image_returns_item);
            title=itemView.findViewById(R.id.text_returns_item_title);
            sku=itemView.findViewById(R.id.text_returns_item_sku);
            refund=itemView.findViewById(R.id.text_returns_item_tuikuan);
            refundType=itemView.findViewById(R.id.text_returns_item_type);
            delete=itemView.findViewById(R.id.text_returns_item_delete);
            details=itemView.findViewById(R.id.text_returns_item_xiangqing);
        }

    }
    public interface onReturnsParticulars{
        void onReturnsResult(int position);
    }
}
